﻿
var personnelname = null;
var age = null;
var gender = null;
var phone = null;
var address = null;
var position = null;

$(function(){
    personnelname = $("#personnelname");
    age = $("#age");
    gender = $("#gender");
    phone = $("#phone");
    address = $("#address");
    position = $("#position");
    addBtn = $("#add");
    backBtn = $("#back");
    //初始化的时候，要把所有的提示信息变为：* 以提示必填项，更灵活，不要写在页面上
    personnelname.next().html("*");
    age.next().html("*");
    gender.next().html("*");
    // phone.next().html("*");
    // address.next().html("*");
    // position.next().html("*");
    /*
     * 验证
     * 失焦\获焦
     * jquery的方法传递
     */
    personnelname.on("blur",function(){
        if(personnelname.val() != null && personnelname.val() != ""){
            validateTip(personnelname.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(personnelname.next(),{"color":"red"},imgNo+" 员工姓名不能为空，请重新输入",false);
        }
    }).on("focus",function(){
        //显示友情提示
        validateTip(personnelname.next(),{"color":"#666666"},"* 请输入员工姓名",false);
    }).focus();

    age.on("blur",function(){
        if(age.val() != null && age.val() != ""){
            validateTip(age.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(age.next(),{"color":"red"},imgNo+" 年龄不能为空，请重新输入",false);
        }
    }).on("focus",function(){
        //显示友情提示
        validateTip(age.next(),{"color":"#666666"},"* 请输入年龄",false);
    }).focus();

    gender.on("blur",function(){
        if(gender.val() != null && gender.val() != ""){
            validateTip(gender.next(),{"color":"green"},imgYes,true);
        }else{
            validateTip(gender.next(),{"color":"red"},imgNo+" 性别不能为空，请重新输入",false);
        }
    }).on("focus",function(){
        //显示友情提示
        validateTip(gender.next(),{"color":"#666666"},"* 请输入性别",false);
    }).focus();

    // phone.on("blur",function(){
    //     if(phone.val() != null && phone.val() != ""){
    //         validateTip(phone.next(),{"color":"green"},imgYes,true);
    //     }else{
    //         validateTip(phone.next(),{"color":"red"},imgNo+" 手机号不能为空，请重新输入",false);
    //     }
    // }).on("focus",function(){
    //     //显示友情提示
    //     validateTip(phone.next(),{"color":"#666666"},"* 请输入手机号",false);
    // }).focus();
    //
    // address.on("blur",function(){
    //     if(address.val() != null && address.val() != ""){
    //         validateTip(address.next(),{"color":"green"},imgYes,true);
    //     }else{
    //         validateTip(address.next(),{"color":"red"},imgNo+" 住址不能为空，请重新输入",false);
    //     }
    // }).on("focus",function(){
    //     //显示友情提示
    //     validateTip(Amount.next(),{"color":"#666666"},"* 请输入住址",false);
    // }).focus();
    //
    // position.on("blur",function(){
    //     if(position.val() != null && Amount.val() != ""){
    //         validateTip(position.next(),{"color":"green"},imgYes,true);
    //     }else{
    //         validateTip(position.next(),{"color":"red"},imgNo+" 职位不能为空，请重新输入",false);
    //     }
    // }).on("focus",function(){
    //     //显示友情提示
    //     validateTip(position.next(),{"color":"#666666"},"* 请输入职位",false);
    // }).focus();

    addBtn.on("click",function(){
        if(personnelname.attr("validateStatus") != "true"){
            personnelname.blur();
        }else if(age.attr("validateStatus") != "true"){
            age.blur();
        }else{
            if(confirm("是否确认提交数据")){
                $("#personnelForm").submit();
            }
        }
    });

    backBtn.on("click",function(){
        if(referer != undefined
            && null != referer
            && "" != referer
            && "null" != referer
            && referer.length > 4){
            window.location.href = referer;
        }else{
            history.back(-1);
        }
    });
});